package cn.zl.web.impl.dashboard;

import cn.zl.common.manage.DashboardManage;
import cn.yunbamboos.rest.service.anno.RestServiceMapping;
import cn.yunbamboos.rest.service.dto.out.BaseOutDTO;
import cn.zl.config.ZLConfig;
import cn.zl.mapper.DeviceMapper;
import cn.zl.mapper.PlatformMapper;
import cn.zl.mapper.StreamProxyMapper;
import cn.zl.mapper.StreamPushMapper;
import cn.zl.mapper.UserMapper;
import cn.zl.mapper.VirtualVideoStreamMapper;
import cn.zl.web.dto.dashboard.DashboardInfoInDTO;
import cn.zl.web.dto.dashboard.DashboardInfoOutDTO;
import cn.zl.web.dto.dashboard.DashboardSipInDTO;
import cn.zl.web.dto.dashboard.DashboardSipOutDTO;
import cn.zl.web.dto.dashboard.DashboardStatisticsInDTO;
import cn.zl.web.dto.dashboard.DashboardStatisticsOutDTO;
import cn.zl.web.inter.dashboard.IDashboardService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("DashboardServiceImpl")
public class DashboardServiceImpl implements IDashboardService {

    @Resource
    private ZLConfig config;
    @Resource
    private DeviceMapper deviceMapper;
    @Resource
    private StreamPushMapper streamPushMapper;
    @Resource
    private StreamProxyMapper streamProxyMapper;
    @Resource
    private VirtualVideoStreamMapper virtualVideoStreamMapper;
    @Resource
    private PlatformMapper platformMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private DashboardManage dashboardManage;

    @RestServiceMapping(url = "/web/dashboard/statistics", name = "仪表盘统计服务", in = DashboardStatisticsInDTO.class, out = DashboardStatisticsOutDTO.class)
    @Override
    public BaseOutDTO statistics(DashboardStatisticsInDTO in) {
        DashboardStatisticsOutDTO out = new DashboardStatisticsOutDTO();
        // 查询设备数
        out.addStatisticsItem("设备", true, deviceMapper.countOnLine(), deviceMapper.total());
        // 查询推流数
        out.addStatisticsItem("推流", true, streamPushMapper.countState(1), streamPushMapper.total());
        // 查询拉流代理
        out.addStatisticsItem("拉流代理", true, streamProxyMapper.countState(1), streamProxyMapper.total());
        // 查询模拟视频流
        out.addStatisticsItem("模拟视频流", true, virtualVideoStreamMapper.countState(1), virtualVideoStreamMapper.total());
        // 国标级联平台
        out.addStatisticsItem("国标级联平台", true, 0, platformMapper.total());
        // 用户
        out.addStatisticsItem("用户", false, 0, userMapper.total());
        return out;
    }

    @RestServiceMapping(url = "/web/dashboard/info", name = "仪表盘服务", in = DashboardInfoInDTO.class, out = DashboardInfoOutDTO.class)
    @Override
    public BaseOutDTO info(DashboardInfoInDTO in) {
        return new DashboardInfoOutDTO(dashboardManage.getCpu(), dashboardManage.getMemory(), dashboardManage.getDisk(), dashboardManage.getNetwork());
    }

    @RestServiceMapping(url = "/web/dashboard/sip", name = "仪表盘查询国标信息服务", in = DashboardSipInDTO.class, out = DashboardSipOutDTO.class)
    @Override
    public BaseOutDTO sip(DashboardSipInDTO in) {
        DashboardSipOutDTO out = new DashboardSipOutDTO();
        out.setId(config.getSIPId());
        out.setDomain(config.getSIPDomain());
        out.setIp(config.getSIPId());
        out.setPort(config.getSIPPort());
        out.setPassword(config.getSIPPassword());
        return out;
    }

}
